//
//  NSDictionary+MY.m
//  JQLive
//
//  Created by Bruce on 2020/3/19.
//  Copyright © 2020 mlqk. All rights reserved.
//

#import "NSDictionary+MY.h"

@implementation NSDictionary (MY)

- (NSData *)JSONDictData
{
    BOOL flag = [NSJSONSerialization isValidJSONObject:self];
    if(flag)
    {
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&error];
        if(!error)
        {
            return jsonData;
        }
    }
    return nil;
}

- (NSString *)JSONWithString
{
    NSString *json = [[NSString alloc] initWithData:[self JSONDictData] encoding:NSUTF8StringEncoding];
    return json;
}

@end
